/*
 * @Author: 一路向阳 tt_sunzhenfeng@163.com
 * @Date: 2024-02-22 22:21:56
 * @LastEditors: 一路向阳 tt_sunzhenfeng@163.com
 * @LastEditTime: 2024-02-22 22:29:29
 * @FilePath: \utils_ts\26.extends和类型推断infer.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
export {};

type FnType<P> = P extends string | number ? P[] : P;

let obj: FnType<number> = [1, 2];
let obj2: FnType<boolean> = false;
let obj3: FnType<string> = ['xx'];

// infer 类型推断
// infer N 取值为name：后面的这个string

type ObjType<T> = T extends {name: infer N, age: infer A} ? [N, A] : null;
let obj4: ObjType<{name: string, age: number}> = ['xx', 1];
let obj5: ObjType<number> = null;
let obj6: ObjType<{name: '张三', age: 18}> = ['张三', 18];